package com.hdu.kdk_feign.factoryBean;

import com.hdu.kdk_feign.handler.FeignInvocationHandler;
import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.Proxy;

public class FeignFactoryBean<T> implements FactoryBean<T> {

    Class<T> targetClass;

    public FeignFactoryBean(Class<T> targetClass) {
        this.targetClass = targetClass;
    }

    @SuppressWarnings("all")
    @Override
    public T getObject() {
        return (T) Proxy.newProxyInstance(
                this.getClass().getClassLoader(),
                new Class[]{targetClass},
                new FeignInvocationHandler()
        );
    }

    @Override
    public Class<T> getObjectType() {
        return targetClass;
    }
}
